<?php

namespace Houdunren\WeChat\Material;

use App\Models\WeChatMaterial;
use hisorange\BrowserDetect\Exceptions\Exception;
use Illuminate\Support\Facades\Http;
use Log;

trait Create
{

    public function add(string $type, string $file)
    {

        //token在基类中，功能列添加至扩展类，可以使用基类的方法
        $api = $this->api . '/material/add_material?access_token=' . $this->token() . '&type=' . $type;

        $response = Http::attach(
            'media',
            file_get_contents($file),
            basename($file)
        )->post($api)->throw()->json();
        return $this->return($response);
    }

    public function getMedia(string $media)
    {
        $api = $this->api . 'material/get_material?access_token=' . $this->token();
        $response = Http::post($api, ['media' => $media])->throw()->json();

        return $this->return($response);
    }
}
